/*
 * @Description:
 * @FilePath: /glm_h5wxgzh/store/modules/message.js
 */
import storage from "@/utils/storage";
import constant from "@/utils/constant";
const message = {
  state: {
    noticeMessageList: storage.get(constant.noticeMessageList),
    fileMessageList: storage.get(constant.fileMessageList),
    messageID: storage.get(constant.messageID),
    messageType: storage.get(constant.messageType),
    messageNotReadeedList: storage.get(constant.messageNotReadeedList),
    messageNotIdList: storage.get(constant.messageNotIdList),
    messageGetNew: storage.get(constant.messageGetNew),
    hasGetMessage:storage.get(constant.hasGetMessage)
  },
  mutations: {
    SET_HASGETMESSAGE: (state, messageBoolean) => {
        state.hasGetMessage=messageBoolean;
      storage.set(constant.hasGetMessage, state.hasGetMessage);
    },
    SET_NOTICELIST: (state, object) => {
      if (!state.noticeMessageList) {
        state.noticeMessageList = [object];
      } else {
        state.noticeMessageList.push(object);
      }
      storage.set(constant.noticeMessageList, state.noticeMessageList);
    },
    SET_FILELIST: (state, object) => {
      if (!state.fileMessageList) {
        state.fileMessageList = [object];
      } else {
        state.fileMessageList.push(object);
      }
      storage.set(constant.fileMessageList, state.fileMessageList);
    },
    SET_MESSAGENOTREADEEDLIST: (state, object) => {
      if (!state.messageNotReadeedList) {
        state.messageNotReadeedList = [object];
      } else {
        if (state.messageNotReadeedList.indexOf(object) === -1) {
          state.messageNotReadeedList.push(object);
        }
      }
      storage.set(constant.messageNotReadeedList, state.messageNotReadeedList);
    },
    REMOVE_MESSAGENOTREADEEDLIST: (state) => {
      state.messageNotReadeedList = [];
      storage.set(constant.messageNotReadeedList, state.messageNotReadeedList);
    },
    SET_MESSAGEGETNEW: (state, messageGetNew) => {
      state.messageGetNew = messageGetNew;
      storage.set(constant.messageGetNew, state.messageGetNew);
    },
    SET_MESSAGENOTIDLIST: (state, object) => {
      if (!state.messageNotIdList) {
        state.messageNotIdList = [object];
      } else {
        if (state.messageNotIdList.indexOf(object) === -1) {
          state.messageNotIdList.push(object);
        }
      }
      storage.set(constant.messageNotIdList, state.messageNotIdList);
    },
    REMOVE_MESSAGENOTIDLIST: (state) => {
      state.messageNotIdList = [];
      storage.set(constant.messageNotIdList, state.messageNotReadeedList);
    },
    SET_MESSAGEID: (state, messageID) => {
      state.messageID = messageID;
      storage.set(constant.messageID, state.messageID);
    },
    SET_MESSAGETYPE: (state, messageType) => {
      state.messageType = messageType;
      storage.set(constant.messageType, state.messageType);
    },
    REMOVE_LIST: (state) => {
      state.noticeMessageList = [];
      state.fileMessageList = [];
      storage.set(constant.noticeMessageList, state.noticeMessageList);
      storage.set(constant.fileMessageList, state.fileMessageList);
    },
  },
};

export default message;
